layui.use(['layer','form','carousel'], function(){
	var layer = layui.layer, form = layui.form, carousel = layui.carousel;

	var is_unlock = localStorage.getItem("room_lock_"+room_id);
    if(room_lock == 1 && is_unlock == null)
    {
        layer.open({
        area: ['420px', '320px'],
        scrollbar: false,
        shade: [0.9, '#1C2225'],
        title: false,
        closeBtn:0,
        skin: 'layui-layer-setmybg',
        type:2, 
            content: ['/index/room_unlock?room_id='+room_id,'no'] 
        });
    }

    $('.login').click(function()
	{
		layer.open({
		area: ['410px', '340px'],
		scrollbar: false,
		title: false,
		skin: 'layui-layer-setmybg',
	  	type:2, 
	  		content: ['/account/login?room_id='+room_id+'','no'] 
		});
	})

    $('.register').click(function()
    {
        layer.open({
        area: ['410px', '340px'],
        scrollbar: false,
        title: false,
        skin: 'layui-layer-setmybg',
        type:2, 
            content: ['/account/register?room_id='+room_id+'','no'] 
        });
    })

    //register
    form.on('submit(register)', function(data){
        $.ajax({
            url: "/account/register",
            data: data.field,
            type: 'post',
            dataType: "json",
            async: false,
            success: function (response) {
                if (response.code == '200') {
                    layer.msg(response.msg);
                    location_reload(1000);
                } else {
                    layer.msg(response.msg);
                    return false;
                }
            }
        })
        return false;
    });

    $('.user_info').click(function()
    {
        layer.open({
        area: ['410px', '340px'],
        scrollbar: false,
        title: false,
        skin: 'layui-layer-setmybg',
        type:2, 
            content: ['/account/user_info','no'] 
        });
    })

    $('.left-menu-url').click(function()
    {
        var menu_url   = $(this).attr('menu_url');
        var menu_id    = $(this).attr('menu_id');
        var menu_name  = $(this).attr('menu_name');
        layer.open({
        area: ['55%', '650px'],
        scrollbar: true,
        title: menu_name,
        skin: 'layui-layer-setmybg',
        type:2, 
        content: menu_url+'?menu_id='+menu_id+'&token='+token,
        });
    })

    carousel.render({
        elem: '#banner'
        ,width: '100%' //设置容器宽度
        ,height: '400px'
        ,arrow: 'always' //始终显示箭头
        //,anim: 'updown' //切换动画方式
    });

    //显示角色icon
    
})

//清屏
$('.clear').click(function(){
    $('.right-msg-meet >li').remove();
})

/**
* 获取角色图标
*/
function getRoleIcon(role)
{
    switch (role)
    {
    	case 0:
            return '/static/images/youke.png';
        //游客
        case 1:
            return '/static/images/youke.png';
        //会员
        case 2:
            return '/static/images/huiyuan.png';
        //讲师
        case 3:
            return '/static/images/teacher.png';
        //助理
        case 4:
            return '/static/images/kefu.png';
        //管理
        case 5:
            return '/static/images/power.png';
        default:
            return '/static/images/youke.png';
    }
}

$('.user-nav > li').on('click',function () {
    $(this).addClass('user-nav-selected').siblings().removeClass('user-nav-selected');
    var c_index = $(this).index();
    if(c_index == 0)
    {
        $('#user-nav2-content').hide();
        $('#user-nav1-content').show();
    }else{
        $('#user-nav1-content').hide();
        $('#user-nav2-content').show();
    }
})

//显示贴图
$(".colorbar").hover(function (){ 
    var colorbar_list = $('.colorbar_list').html();
    layer.tips(''+colorbar_list+'', '.colorbar', {
      tips: [1, '#333'],
      time: 4000
    });
},function (){  

}); 

//显示角色icon
function sendColorbar(e)
{
    var color_content = '';
    switch (e) {
        case 1:
        color_content = '<img src="/static/images/zyg.gif">';
        break;
        case 2:
        color_content = '<img src="/static/images/dyg.gif">';
        break;
        case 3:
        color_content = '<img src="/static/images/xh.gif">';
        break;
        case 4:
        color_content = '<img src="/static/images/zs.gif">';
        break;
    }
    //插入内容框
    $('#message_content').html(color_content);
}

//显示表情
$("#message_content").emoji({
    button: ".face",
    showTab: false,
    animation: 'slide',
    position: 'topLeft',
    icons: [{
        name: "QQ表情",
        path: "/static/emoji/dist/img/qq/",
        maxNum: 91,
        excludeNums: [41, 45, 54],
        file: ".gif"
    }]
});

//复制地址
function copyUrl()
{
    var Url2 = window.location.href;
    var oInput = document.createElement('input');
    oInput.value = Url2;
    document.body.appendChild(oInput);
    oInput.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    oInput.className = 'oInput';
    oInput.style.display='none';
    alert('复制成功，可粘贴');
}
//显示二维码
$(".phoneToView").hover(function (){ 
    var phoneToViewCode = $('#phoneToViewCode').html();
    layer.tips(''+phoneToViewCode+'', '.phoneToView', {
      tips: [1, '#fff'],
      time: 8000
    });
},function (){  
    var index = layer.tips();
    layer.close(index);
}); 

//放大图片
$(document).on('click','.message_img',function () {
    var img_src = $(this).attr('src');
    layer.open({
        area: ['65%', '650px'],
        scrollbar: true,
        title: false,
        skin: 'layui-layer-setmybg',
        type:1, 
            content: '<img src='+img_src+' style="width:100%;height:100%;">' 
    });
})

//保存到桌面
function toDesktop()
{ 
    var sUrl = window.location.href;
    var title =document.title;
    window.location.href = '/index/save_url?url='+sUrl+'&title='+title;
} 